package co.edu.unal.satacredito.administration.util;

import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.servlet.http.HttpSession;

public class SessionUtil {

	/**
	 * 
	 * @param externalContext
	 * @param key
	 * @param value
	 */
	public static void storeInSession(ExternalContext externalContext,
			String key, Object value) {
		Map<String, Object> sessionMap = externalContext.getSessionMap();
		sessionMap.put(key, value);
	}
	
	/**
	 * 
	 * @param externalContext
	 * @param key
	 * @return null if no value was found in the map with that key
	 */
	public static Object retrieveFromSession(ExternalContext externalContext, String key){
		Map<String, Object> sessionMap = externalContext.getSessionMap();
		return sessionMap.get(key);
	}
	
	/**
	 * 
	 * @param externalContext
	 */
	public static void closeSession(ExternalContext externalContext) {
		Object session = externalContext.getSession(false);
		HttpSession httpSession = (HttpSession) session;
		httpSession.invalidate();
	}

}
